<template>
    <div>
        <Form ref="parametersForm" :model="methodParametersForm.repaymentMethods" :rules="methodParametersValidate"
              :label-width="200">
            <div v-if="repaymentMethod=='2'">
                <Alert>
                    <h2>分段贷参数</h2>
                </Alert>
                <Row>
                    <Col span="10">
                        <FormItem label="尾款基准" prop="finalPaymentBenchmark">
                            <Select v-model="methodParametersForm.repaymentMethods.finalPaymentBenchmark"
                                    placeholder="请选择" :disabled="isreadonly"
                                    style="margin-right:10px;width:150px">
                                <Option
                                    :value="item.value"
                                    v-for="(item,index) in finalPaymentBenchmark"
                                    :key="index"
                                >{{item.title}}
                                </Option>
                            </Select>
                        </FormItem>
                    </Col>
                    <Col span="10">
                        <FormItem label="尾款计算逻辑" prop="finalPaymentCalculationLogic" :required=false>
                            <Select v-model="methodParametersForm.repaymentMethods.finalPaymentCalculationLogic"
                                    :disabled="isfinalreadonly"
                                    placeholder="请选择" style="margin-right:10px;width:150px">
                                <Option
                                    :value="item.value"
                                    v-for="(item,index) in finalPaymentCalculationLogic"
                                    :key="index"
                                >{{item.title}}
                                </Option>
                            </Select>
                        </FormItem>
                    </Col>
                </Row>
                <Row>
                    <Col>
                        <Row class="operation">
                            <Button @click="add" icon="md-add" type="primary" v-show="parentParam.status!=3">新增
                            </Button>
                        </Row>
                        <Row>
                            <Table :columns="columns" :data="methodParametersForm.data" :loading="loading"
                                   border ref="table">
                                <template slot="action" slot-scope="{ row, index }">
                                    <Button @click="edit(row,index)" size="small" style="margin-right:5px"
                                            v-show="parentParam.status!=3"
                                            type="primary">编辑
                                    </Button>
                                    <Button @click="remove(row,index)" size="small" type="error"
                                            v-show="parentParam.status!=3">
                                        删除
                                    </Button>
                                </template>
                                <template slot="paymentByStages" slot-scope="{ row, index }">
                                    <span>{{setCalculationOperationTypeTitle(row.paymentByStages)}}</span>
                                </template>
                                <template slot="proportionRepaymentSections" slot-scope="{ row, index }">
                                    <span>{{row.proportionRepaymentSections!=null?row.proportionRepaymentSections+'%':""}}</span>
                                </template>
                                <template slot="repaymentAmountStages" slot-scope="{ row, index }">
                                    <span>{{row.repaymentAmountStages!=null?'￥'+row.repaymentAmountStages:""}}</span>
                                </template>
                            </Table>
                        </Row>
                        <Modal :title="modalTitle" v-model="modalVisible" :mask-closable='false' :width="500"
                               :closable="false"
                               :styles="{top: '90px'}">
                            <Form ref="installmentsForm" :model="installmentsForm" :label-width="200"
                                  :rules="installmentsFormValidate">
                                <FormItem label="分段还款期数" prop="numberInstallments">
                                    <InputNumber :min="1" v-model="installmentsForm.numberInstallments"
                                                 autocomplete="off" :disabled="isreadonly"
                                                 style="margin-right:10px;width:150px"
                                    />
                                </FormItem>
                                <FormItem label="分段还款方式" prop="paymentByStages">
                                    <Select v-model="installmentsForm.paymentByStages" placeholder="请选择" @on-change="changePaymentByStages"
                                            :disabled="isreadonly"
                                            style="margin-right:10px;width:150px">
                                        <Option
                                            :value="item.value"
                                            v-for="(item,index) in calculationOperationType"
                                            :key="index"
                                        >{{item.title}}
                                        </Option>
                                    </Select>
                                </FormItem>
                                <div v-if="installmentsForm.paymentByStages=='1'">
                                    <FormItem label="分段还款金额" prop="repaymentAmountStages">
                                        <InputNumber :min='0' v-model="installmentsForm.repaymentAmountStages"
                                                     :step="100" autocomplete="off" :disabled="isreadonly"
                                                     :formatter="value => `￥ ${value}`.replace(/\B(?=(\d{3})+(?!\d))/g, ',')"
                                                     :parser="value => value.replace(/\￥\s?|(,*)/g, '')"
                                                     style="margin-right:10px;width:150px"></InputNumber>
                                    </FormItem>
                                </div>
                                <div v-if="installmentsForm.paymentByStages=='0'">
                                    <FormItem label="分段还款比例%" prop="proportionRepaymentSections">
                                        <InputNumber :min='0' v-model="installmentsForm.proportionRepaymentSections"
                                                     autocomplete="off"
                                                     :formatter="value => `${value}`"
                                                     style="margin-right:10px;width:150px"/>
                                    </FormItem>
                                </div>
                            </Form>
                            <div slot="footer">
                                <Button type="text" @click="cancel">取消</Button>
                                <Button type="primary" @click="okClick">确定</Button>
                            </div>
                        </Modal>
                    </Col>
                </Row>
            </div>
            <div v-if="repaymentMethod=='3'">
                <Alert>
                    <h2>尾款贷参数</h2>
                </Alert>
                <Row>
                    <Col span="10">
                        <FormItem label="尾款基准" prop="finalPaymentBenchmark">
                            <Select v-model="methodParametersForm.repaymentMethods.finalPaymentBenchmark"
                                    placeholder="请选择" :disabled="isreadonly"
                                    style="margin-right:10px;width:150px">
                                <Option
                                    :value="item.value"
                                    v-for="(item,index) in finalPaymentBenchmark"
                                    :key="index"
                                >{{item.title}}
                                </Option>
                            </Select>
                        </FormItem>
                    </Col>
                    <Col span="10">
                        <FormItem label="尾款计算逻辑" prop="finalPaymentCalculationLogic" :required=false>
                            <Select v-model="methodParametersForm.repaymentMethods.finalPaymentCalculationLogic"
                                    placeholder="请选择" :disabled="isfinalreadonly" style="margin-right:10px;width:150px">
                                <Option
                                    :value="item.value"
                                    v-for="(item,index) in finalPaymentCalculationLogic"
                                    :key="index"
                                >{{item.title}}
                                </Option>
                            </Select>
                        </FormItem>
                    </Col>
                </Row>
                <Row>
                    <Col span="10">
                        <FormItem label="尾款区间选择" prop="intervalSelectionFinalPayment" :required=false>
                            <Select
                                v-model="methodParametersForm.repaymentMethods.intervalSelectionFinalPayment"   @on-change="changeIntervalSelectionFinalPayment"
                                placeholder="请选择" :disabled="isreadonly" style="margin-right:10px;width:150px"
                            >
                                <Option
                                    :value="item.value"
                                    v-for="(item,index) in calculationOperationType"
                                    :key="index"
                                >{{item.title}}
                                </Option>
                            </Select>
                        </FormItem>
                    </Col>
                </Row>
                <div v-if="methodParametersForm.repaymentMethods.intervalSelectionFinalPayment=='0'">
                    <Row>
                        <Col span="10">
                            <FormItem label="尾款区间起%" prop="fromBalancePaymentInterval">
                                <InputNumber :min='0' :max="100"
                                             v-model="methodParametersForm.repaymentMethods.fromBalancePaymentInterval"
                                             autocomplete="off" :disabled="isreadonly" @on-change="changeFromBalancePaymentInterval"
                                             :formatter="value => `${value}`"
                                             style="margin-right:10px;width:150px"
                                />
                            </FormItem>
                        </Col>
                        <Col span="10">
                            <FormItem label="尾款区间止%" prop="endBalancePaymentRange" :required=false>
                                <InputNumber :min='0' :max="100" :disabled="isreadonly" @on-change="changeEndBalancePaymentRange"
                                             v-model="methodParametersForm.repaymentMethods.endBalancePaymentRange"
                                             autocomplete="off"
                                             :formatter="value => `${value}`"
                                             style="margin-right:10px;width:150px"/>
                            </FormItem>
                        </Col>
                    </Row>
                </div>
                <div v-if="methodParametersForm.repaymentMethods.intervalSelectionFinalPayment=='1'">
                    <Row>
                        <Col span="10">
                            <FormItem label="尾款区间起" prop="fromBalancePaymentInterval">
                                <InputNumber v-model="methodParametersForm.repaymentMethods.fromBalancePaymentInterval"
                                             :step="100" autocomplete="off" :disabled="isreadonly" @on-change="changeFromBalancePaymentInterval"
                                             :formatter="value => `￥ ${value}`.replace(/\B(?=(\d{3})+(?!\d))/g, ',')"
                                             :parser="value => value.replace(/\￥\s?|(,*)/g, '')"
                                             style="margin-right:10px;width:150px"></InputNumber>
                            </FormItem>
                        </Col>
                        <Col span="10">
                            <FormItem label="尾款区间止" prop="endBalancePaymentRange" :required=false>
                                <InputNumber v-model="methodParametersForm.repaymentMethods.endBalancePaymentRange"
                                             :step="100" autocomplete="off" :disabled="isreadonly"  @on-change="changeEndBalancePaymentRange"
                                             :formatter="value => `￥ ${value}`.replace(/\B(?=(\d{3})+(?!\d))/g, ',')"
                                             :parser="value => value.replace(/\￥\s?|(,*)/g, '')"
                                             style="margin-right:10px;width:150px"></InputNumber>
                            </FormItem>
                        </Col>
                    </Row>
                </div>
            </div>
            <div v-if="repaymentMethod=='4'">
                <Alert>
                    <h2>阶梯贷参数</h2>
                </Alert>
                <Row>
                    <Col span="10">
                        <FormItem label="阶梯贷浮动比例（±%）" prop="floatingProportionStepLoan">
                            <InputNumber :min="-99" :max="100 "
                                         v-model="methodParametersForm.repaymentMethods.floatingProportionStepLoan"
                                         :formatter="value => `${value}`"
                                         autocomplete="off"
                                         :disabled="isreadonly" style="margin-right:10px;width:150px"/>
                        </FormItem>
                    </Col>
                    <Col span="10">
                        <FormItem label="每个阶梯期数" prop="numberStepsPerStep">
                            <InputNumber :min='1' v-model="methodParametersForm.repaymentMethods.numberStepsPerStep"
                                         autocomplete="off" :disabled="isreadonly"
                                         style="margin-right:10px;width:150px"/>
                        </FormItem>
                    </Col>
                </Row>
            </div>
            <div v-if="repaymentMethod=='5'">
                <Alert>
                    <h2>任意贷参数</h2>
                </Alert>
                <Row>
                    <Col span="10">
                        <FormItem label="调整后月供最小值限定方式" prop="adjustedMinimumMode">
                            <Select v-model="methodParametersForm.repaymentMethods.adjustedMinimumMode"
                                    placeholder="请选择" :disabled="isreadonly"
                                    style="margin-right:10px;width:150px">
                                <Option
                                    :value="item.value"
                                    v-for="(item,index) in calculationOperationType"
                                    :key="index"
                                >{{item.title}}
                                </Option>
                            </Select>
                        </FormItem>
                    </Col>
                    <div v-if="methodParametersForm.repaymentMethods.adjustedMinimumMode=='1'">
                        <Col span="10">
                            <FormItem label="调整后月供≥" prop="adjustedMonthlyPayments">
                                <InputNumber :min='0'
                                             v-model="methodParametersForm.repaymentMethods.adjustedMonthlyPayments"
                                             :step="100" autocomplete="off" :disabled="isreadonly"
                                             :formatter="value => `￥ ${value}`.replace(/\B(?=(\d{3})+(?!\d))/g, ',')"
                                             :parser="value => value.replace(/\￥\s?|(,*)/g, '')"
                                             style="margin-right:10px;width:150px"></InputNumber>
                            </FormItem>
                        </Col>
                    </div>
                    <div v-if="methodParametersForm.repaymentMethods.adjustedMinimumMode=='0'">
                        <Col span="10">
                            <FormItem label="调整后月供≥总融资额*（%）" prop="monthlyPaymentPercentage">
                                <InputNumber :max='100' :min='0' :disabled="isreadonly"
                                             v-model="methodParametersForm.repaymentMethods.monthlyPaymentPercentage"
                                             autocomplete="off"
                                             :formatter="value => `${value}`"
                                             style="margin-right:10px;width:150px"/>

                            </FormItem>
                        </Col>
                    </div>
                </Row>

                <Row>
                    <Col span="10">
                        <FormItem label="前n期还款最小值限定方式" prop="firstNMinimumLimit">
                            <Select v-model="methodParametersForm.repaymentMethods.firstNMinimumLimit"
                                    placeholder="请选择" :disabled="isreadonly"
                                    style="margin-right:10px;width:150px">
                                <Option
                                    :value="item.value"
                                    v-for="(item,index) in calculationOperationType"
                                    :key="index"
                                >{{item.title}}
                                </Option>
                            </Select>
                        </FormItem>
                    </Col>
                    <div v-if="methodParametersForm.repaymentMethods.firstNMinimumLimit=='1'">
                        <Col span="10">
                            <FormItem label="前N期还款总额≥" prop="totalAmountInstalments">
                                <InputNumber :min='0'
                                             v-model="methodParametersForm.repaymentMethods.totalAmountInstalments"
                                             :step="100" autocomplete="off" :disabled="isreadonly"
                                             :formatter="value => `￥ ${value}`.replace(/\B(?=(\d{3})+(?!\d))/g, ',')"
                                             :parser="value => value.replace(/\￥\s?|(,*)/g, '')"
                                             style="margin-right:10px;width:150px"></InputNumber>
                            </FormItem>
                        </Col>
                    </div>
                    <div v-if="methodParametersForm.repaymentMethods.firstNMinimumLimit=='0'">
                        <Col span="10">
                            <FormItem label="前N期还款总额≥总融资额*（%）" prop="percentageTotalRepayment">
                                <InputNumber :max="100" :min='0'
                                             v-model="methodParametersForm.repaymentMethods.percentageTotalRepayment"
                                             autocomplete="off" :disabled="isreadonly"
                                             :formatter="value => `${value}`"
                                             style="margin-right:10px;width:150px"/>
                            </FormItem>
                        </Col>
                    </div>
                </Row>
                <Row>
                    <Col span="10">
                        <FormItem label="任意贷期数设定(n)" prop="setAnyNumberCredits">
                            <InputNumber :min='1' v-model="methodParametersForm.repaymentMethods.setAnyNumberCredits"
                                         autocomplete="off" :disabled="isreadonly"
                                         style="margin-right:10px;width:150px"/>
                        </FormItem>
                    </Col>
                </Row>
            </div>
            <div v-if="repaymentMethod=='6'">
                <Alert>
                    <h2>结构化</h2>
                </Alert>
                <Row>
                    <Col span="12">
                        <FormItem label="还款类型" prop="paymentType">
                            <Select v-model="methodParametersForm.repaymentMethods.paymentType"
                                    placeholder="请选择" :disabled="isreadonly" @on-change="changePaymentType"
                                    style="margin-right:10px;width:150px">
                                <Option
                                    :value="item.value"
                                    v-for="(item,index) in paymentType"
                                    :key="index"
                                >{{item.title}}
                                </Option>
                            </Select>
                        </FormItem>
                    </Col>
                    <Col span="12">
                        <FormItem label="结构化期数(n)" prop="setAnyNumberCredits">
                            <InputNumber :min='1' v-model="methodParametersForm.repaymentMethods.setAnyNumberCredits"
                                         autocomplete="off" :disabled="isreadonly"
                                         style="margin-right:10px;width:150px"/>
                        </FormItem>
                    </Col>
                </Row>
                <Row>
                    <Col span="12">
                        <FormItem label="还款金额" prop="monthlySupplyAmount" v-if="methodParametersForm.repaymentMethods.paymentType!=1">
                            <InputNumber :min='0' v-model="methodParametersForm.repaymentMethods.monthlySupplyAmount"
                                         :step="100" autocomplete="off" :disabled="isreadonly"
                                         :formatter="value => `￥ ${value}`.replace(/\B(?=(\d{3})+(?!\d))/g, ',')"
                                         :parser="value => value.replace(/\￥\s?|(,*)/g, '')"
                                         style="margin-right:10px;width:150px"></InputNumber>
                        </FormItem>
                    </Col>
                </Row>
            </div>
            <br>
        </Form>
    </div>
</template>
<script>
    import * as utils from '_p/afs-apply/assets/js/utils.js'
    import {getByTypes} from "_p/basic/api/admin/datadic";
    import {deepClone} from "@/libs/utils/ObjectClone";

    export default {
        name: "product-proposal-information",
        props: {
            parentParam: {
                Object,
            },
            methodParametersForm: {
                Object
            },
            repaymentMethod: {
                Object
            },
        },
        data() {
            const validateDicmal = (rule, value, callback) => {
                if (value) {
                    if (!utils.isTwoDicmal(value)) {
                        callback(new Error("格式数字且最多为两位小数"))
                    } else {
                        callback();
                    }
                }
            };
            const validateInteger = (rule, value, callback) => {
                if (!utils.isPositiveInteger(value)) {
                    callback(new Error("格式为正整数"))
                } else {
                    callback();
                }
            };
            let validateFromBalancePaymentInterval = (rule, value, callback) => {
                let values = this.methodParametersForm.repaymentMethods.endBalancePaymentRange;
                if (values != null) {
                    if (value > values) {
                        callback(new Error("尾款区间止要大于等于尾款区间起"));
                    } else {
                        callback();
                    }
                }

            };
            let validateEndBalancePaymentRange = (rule, value, callback) => {
                let values = this.methodParametersForm.repaymentMethods.fromBalancePaymentInterval;
                if (values != null) {
                    if (value < values) {
                        callback(new Error("尾款区间止要大于等于尾款区间起"));
                    } else {
                        callback();
                    }
                }
            };
            return {
                loading: false,
                isreadonly: false,
                isfinalreadonly: false,
                modalTitle: "",
                modalVisible: false,
                stagesRequired: false,
                sectionsRequired: false,
                modalType: null,
                installmentsForms: {},
                installmentsForm: {
                    numberInstallments: null,
                    paymentByStages: null,
                    repaymentAmountStages: null,
                    proportionRepaymentSections: null,
                },
                methodParametersFormValidate: [],
                finalPaymentBenchmark: [],
                paymentType: [],
                calculationOperationType: [],
                finalPaymentCalculationLogic: [],
                installmentsFormValidate: {
                    numberInstallments: [
                        {required: true, message: "分段还款期数不能为空", type: 'number', trigger: "change"},
                    ],
                    paymentByStages: [
                        {required: true, message: "分段还款方式不能为空", trigger: "change"},
                    ],
                    repaymentAmountStages: [
                        {required: true, message: "分段还款金额不能为空", type: 'number', trigger: "change"},
                    ],
                    proportionRepaymentSections: [
                        {required: true, message: "分段还款比例不能为空", type: 'number', trigger: "change"},
                    ],
                },
                methodParametersValidate: {
                    finalPaymentBenchmark: [
                        {required: true, message: "尾款基准不能为空", trigger: "change"},
                    ],
                    finalPaymentCalculationLogic: [
                        {required: true, message: "尾款计算逻辑不能为空", trigger: "change"},
                    ],
                    intervalSelectionFinalPayment: [
                        {required: true, message: "尾款区间选择不能为空", trigger: "change"},
                    ],
                    fromBalancePaymentInterval: [
                        {required: true, message: "尾款区间起不能为空", type: 'number', trigger: "change"},
                        {validator: validateFromBalancePaymentInterval, trigger: "change"}

                    ],
                    endBalancePaymentRange: [
                        {required: true, message: "尾款区间止不能为空", type: 'number', trigger: "change"},
                        {validator: validateEndBalancePaymentRange, trigger: "change"}
                    ],
                    floatingProportionStepLoan: [
                        {required: true, message: "阶梯贷浮动比例（±%）不能为空", type: 'number', trigger: "change"},
                    ],
                    numberStepsPerStep: [
                        {required: true, message: "每个阶梯期数不能为空", type: 'number', trigger: "change"},
                    ],
                    adjustedMinimumMode: [
                        {required: true, message: "调整后月供最小值限定方式≥不能为空", trigger: "change"},
                    ],
                    adjustedMonthlyPayments: [
                        {required: true, message: "调整后月供≥不能为空", type: 'number', trigger: "change"},
                    ],
                    monthlyPaymentPercentage: [
                        {required: true, message: "调整后月供≥总融资额*（%）不能为空", type: 'number', trigger: "change"},
                    ],
                    firstNMinimumLimit: [
                        {required: true, message: "前n期还款最小值限定方式不能为空", trigger: "change"},
                    ],
                    setAnyNumberCredits: [
                        {required: true, message: "任意贷期数设定(n)不能为空", type: 'number', trigger: "change"},
                    ],
                    totalAmountInstalments: [
                        {required: true, message: "前N期还款总额≥不能为空", type: 'number', trigger: "change"},
                    ],
                    percentageTotalRepayment: [
                        {required: true, message: "前N期还款总额≥总融资额*（%）不能为空", type: 'number', trigger: "change"},
                    ],
                    monthlySupplyAmount: [
                        {required: true, message: "月供金额不能为空", type: 'number', trigger: "change"},
                    ],
                    paymentType: [
                        {required: true, message: "还款类型不能为空", trigger: "change"},
                    ],
                },
                columns: [
                    {
                        title: "分段还款期数",
                        key: "numberInstallments"
                    },
                    {
                        title: "分段还款方式",
                        key: "paymentByStages",
                        slot: "paymentByStages",
                        align: "center"
                    },
                    {
                        title: "分段还款金额",
                        key: "repaymentAmountStages",
                        slot: "repaymentAmountStages",
                        tooltip: true
                    },
                    {
                        title: "分段还款比例",
                        key: "proportionRepaymentSections",
                        slot: "proportionRepaymentSections",
                        align: "center"
                    },
                    {
                        title: "操作",
                        key: "action",
                        align: "center",
                        slot: "action"
                    }
                ]
            }
        },

        mounted() {
            this.initDatadic();
            let {status} = this.parentParam;
            this.status = status;
            if ('3' == status) {
                this.isreadonly = true;
                this.isfinalreadonly = true;
            }
        },
        methods: {
            initDatadic() {
                //数据字典
                let arr = ["finalPaymentCalculationLogic", "calculationOperationType", "finalPaymentBenchmark","paymentType"];
                getByTypes(arr).then(res => {
                    if (res.code === "0000") {
                        this.finalPaymentBenchmark.push(...res.data.finalPaymentBenchmark);
                        this.finalPaymentCalculationLogic.push(...res.data.finalPaymentCalculationLogic);
                        this.calculationOperationType.push(...res.data.calculationOperationType);
                        this.paymentType.push(...res.data.paymentType);
                    }
                });
            },
            setCalculationOperationTypeTitle(val) {
                let dic = {}
                this.calculationOperationType.forEach(column => {
                    if (column.value === val) {
                        dic = column;
                    }
                });
                return dic.title;
            },
            //子组件校验，传递到父组件
            validateForm() {
                let flag = true
                this.$refs['parametersForm'].validate(valid => {
                    if (valid) {
                        if (this.productPlanRate.loanPeriodStart > this.productPlanRate.loanPeriodEnd) {
                            this.$Message.error("贷款期数起不能大于贷款期数止");
                            flag = false
                            return;
                        }
                    } else {
                        flag = false
                    }
                })
                return flag
            },
            add() {
                this.modalTitle = "新增";
                this.modalType = '0';
                this.installmentsForm = {
                    numberInstallments: null,
                    paymentByStages: null,
                    repaymentAmountStages: null,
                    proportionRepaymentSections: null,
                },
                    this.modalVisible = true;
            },
            cancel() {
                this.modalTitle = "";
                if ("1" == this.modalType) {
                    this.methodParametersForm.data.push(this.installmentsForms);
                }
                this.modalVisible = false;
            },
            okClick() {
                let self = this;
                self.$refs.installmentsForm.validate(validate => {
                    if (validate) {
                        this.methodParametersForm.data.push(this.installmentsForm);
                        self.modalVisible = false;
                    } else {
                        self.$Message.error("数据错误");
                    }
                })
            },
            remove(row, index) {
                let self = this;
                self.$Modal.confirm({
                    title: "确认删除",
                    content: "您确认要删除?",
                    onOk: () => {
                        self.methodParametersForm.data.splice(index, 1);
                    }
                });
            },
            edit(row, index) {
                this.modalTitle = '编辑';
                this.modalType = '1';
                this.installmentsForms = (deepClone(row));
                this.installmentsForm = (deepClone(row));
                this.methodParametersForm.data.splice(index, 1);
                this.modalVisible = true;
            },
            changePaymentByStages(v){
                if ('0' == v) {
                    this.installmentsForm.repaymentAmountStages = null;
                } else if ('1' == v) {
                    this.installmentsForm.proportionRepaymentSections = null;
                }
            },
            changeFromBalancePaymentInterval(v){
                this.$refs.parametersForm.validateField('endBalancePaymentRange');
            },
            changeEndBalancePaymentRange(v){
                this.$refs.parametersForm.validateField('fromBalancePaymentInterval');
            },

            changeIntervalSelectionFinalPayment(v){
                this.methodParametersForm.repaymentMethods.fromBalancePaymentInterval=null;
                this.methodParametersForm.repaymentMethods.endBalancePaymentRange=null;
            },
            //还款类型变化
            changePaymentType(val){
                if(val==0){
                    this.methodParametersForm.repaymentMethods.monthlySupplyAmount = 0;
                }
            },
        },
        watch: {
            'methodParametersForm.repaymentMethods.adjustedMinimumMode': {
                handler: function (val, oldVal) {
                    if ('1' == val && val !== oldVal) {
                        this.methodParametersForm.repaymentMethods.monthlyPaymentPercentage = null;
                    } else if ('0' == val && val !== oldVal) {
                        this.methodParametersForm.repaymentMethods.adjustedMonthlyPayments = null;
                    }
                },
            },
        },
        watch: {
            'repaymentMethod': {
                handler: function (val, oldVal) {
                    if (val !== oldVal && oldVal !== null && val !== "" && oldVal !== "") {
                        this.$nextTick(() => {
                            this.$refs.parametersForm.resetFields();
                            let parm = {
                                repaymentMethods: {
                                    finalPaymentBenchmark: null,
                                    finalPaymentCalculationLogic: '1',
                                    intervalSelectionFinalPayment: null,
                                    fromBalancePaymentInterval: null,
                                    endBalancePaymentRange: null,
                                    floatingProportionStepLoan: null,
                                    numberStepsPerStep: null,
                                    adjustedMinimumMode: null,
                                    adjustedMonthlyPayments: null,
                                    monthlyPaymentPercentage: null,
                                    firstNMinimumLimit: null,
                                    setAnyNumberCredits: null,
                                    percentageTotalRepayment: null,
                                    monthlySupplyAmount: null,
                                    totalAmountInstalments: null,
                                    paymentType:null,
                                },
                                data: []
                            };
                            this.$emit('methodParametersChange', parm);
                        });
                    }
                },
            }
        },
    }
</script>
<style scoped>
</style>
